import { useDetail, useList } from "@/hooks";
import { getUserInfoUrl, getUserTypeValue } from "@/command/apiTool";
import { getAction } from "@/command/netTool";
import * as vant from "vant";
const { showFailToast, showSuccessToast } = vant;
export const useRequest = () => {
  const [rootData] = useDetail(
    "/api/H5/util/getProductRoot", [],
    {
      callBack: (data: any[]) => {
        return data.map((e) => ({ text: e.name, value: e.id, children: [] }))
      }
    });
  // 最新快讯
  const [newInfoList] = useDetail(
    getUserInfoUrl({
      dh: "/api/H5/gov/richTraceSourceApply/large/queryTraceabilityFlash",
      xh: "/api/H5/gov/richTraceSourceApply/small/queryTraceabilityFlash",
    }),
    []
  );
  // 申请记录
  const [applicationRecord] = useDetail(
    getUserInfoUrl({
      dh: "",
      xh: "/api/H5/gov/richTraceSourceApply/small/queryApplicationRecord",
    }),
    []
  );

  const getLevelData = (item: any) => {
    getAction(`/api/H5/util/getProductLevel?id=${item.value}`).then((e) => {
      if (item.selectedOptions[item.tabIndex]['children']) {
        item.selectedOptions[item.tabIndex]['children'] = e.map((el: any) => ({ ...el, text: el.label })) as never
      }
    })
  }
  return {
    newInfoList,
    applicationRecord,
    rootData,
    getLevelData
  };
};
